package cloud.xlh.beanpostprocessor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/2/3 14:38
 * @ Description: 中间件细粒度解密程序
 */
@Component
@Slf4j
public class DataSourcePropertiesBeanPostProcessor implements BeanPostProcessor {
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof DataSourceProperties) {
            log.info("DataSourcePropertiesBeanPostProcessor postProcessAfterInitialization run...");
            DataSourceProperties dataSourceProperties = (DataSourceProperties) bean;
            dataSourceProperties.setPassword("root");
            dataSourceProperties.setUsername("root");
        }
        return bean;
    }
}
